1 Setup

print(paste0('../../../', '../motif_analysis/output/first_try/report/summary_table.txt'))
## [1] "../../../../motif_analysis/output/first_try/report/summary_table.txt"
if('../motif_analysis/output/first_try/report/summary_table.txt' != '') {
  highlight.snp.df <- read.table(paste0('../../../', '../motif_analysis/output/first_try/report/summary_table.txt'), header = T)
} else {
  highlight.snp.df <- NULL
}
rds.dirs <- strsplit('output/heart_motif_snp/Heart_Atrial_Appendage/fine-map__susie/,output/heart_motif_snp/Heart_Left_Ventricle/fine-map__susie/,output/heart_motif_snp/Muscle_Skeletal/fine-map__susie/', ',')[[1]]
output <- list()
for(rds.dir in rds.dirs) {
  tissue <- basename(dirname(rds.dir))
  cat('#', tissue, '
', '
')
  rdss <- Sys.glob(paste0('../../../', rds.dir, '/', '*.rds'))
  for(rds in rdss) {
    gene <- sub('.rds', '', basename(rds), fixed = T)
    cat('##', gene, '\n', '\n')
    out <- readRDS(rds)
    cs <- susieR::susie_get_CS(out$fitted, t(data.matrix(out$X[, -ncol(out$X)])), coverage = .95)

    # output[[length(output) + 1]] <- paste0(capture.output(pander(cs$purity)), collapse = '\n')
    pander(cs$purity)

    pip <- susieR::susie_get_PIP(out$fitted, cs$cs_index)
    coordinate <- as.numeric(str_match(out$X$SNP_ID, '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2])
    df <- data.frame(coordinate = coordinate, pip = pip)
    df$cs <- -1
    if(length(cs$cs_index) != 0) {
      for(i in 1 : length(cs$cs_index)) {
        df$cs[cs$cs[[i]]] <- cs$cs_index[i]
      }
    }
    p <- ggplot(df) + geom_point(aes(x = coordinate, y = pip, color = factor(cs)))
    p <- p + ggtitle('PIP (red line: leadingSNP; blue line: candidateSNP)')
    if(!is.null(highlight.snp.df)) {
      highlight.snp <- highlight.snp.df[highlight.snp.df$ensembl_gene_id == str_match(gene, '([A-Za-z0-9]+).[A-Za-z0-9]+')[, 2] & highlight.snp.df$tissue == tissue, ]
      leading.snp <- as.numeric(str_match(highlight.snp$leading_eqtl[1], '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2])
      candidate.snp <- unique(as.numeric(str_match(highlight.snp$motif_snp, '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2]))
      p <- p + geom_vline(xintercept = candidate.snp, color = 'blue')
    }
    p <- p + geom_vline(xintercept = leading.snp, color = 'red')
    x <- as.widget(ggplotly(p))
    output[[length(output) + 1]] <- x
    cat(renderTags(x)$html)
    cat('\n', '\n')
  }
}

2 Heart_Atrial_Appendage

2.1 ENSG00000103091.10

min.abs.corr mean.abs.corr median.abs.corr
0.9986 0.9993 0.9993
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.2 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.9414 0.978 0.9991
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.3 ENSG00000114450.5

min.abs.corr mean.abs.corr median.abs.corr
0.999 0.9995 0.9997
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.4 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
0.8997 0.9586 0.9656
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.5 ENSG00000141542.6

min.abs.corr mean.abs.corr median.abs.corr
0.9849 0.9925 0.9925
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.6 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.9108 0.9665 0.9659
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.7 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.956 0.9954 1
1 1 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.8 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.9 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
0.9589 0.992 0.9909
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.10 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3 Heart_Left_Ventricle

3.1 ENSG00000103091.10

min.abs.corr mean.abs.corr median.abs.corr
0.8809 0.9333 0.9121
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.2 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.9988 0.9995 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.3 ENSG00000114450.5

min.abs.corr mean.abs.corr median.abs.corr
0.9912 0.9961 0.9981
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.4 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
0.9485 0.9835 0.9852
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.5 ENSG00000141542.6

min.abs.corr mean.abs.corr median.abs.corr
0.9885 0.9948 0.9944
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.6 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.9884 0.9959 0.9947
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.7 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.9815 0.9987 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.8 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
1 1 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.9 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
0.8145 0.9836 0.9896
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.10 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
0.8911 0.9721 0.9706
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4 Muscle_Skeletal

4.1 ENSG00000103091.10

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.2 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.9284 0.9652 0.9822
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.3 ENSG00000114450.5

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.4 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
0.921 0.9727 0.9728
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.5 ENSG00000141542.6

min.abs.corr mean.abs.corr median.abs.corr
0.9905 0.9952 0.9952
0.9467 0.9819 0.9943
1 1 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.6 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.8583 0.9646 0.9685
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.7 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.7157 0.9317 0.9716
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.8 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.9 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.10 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
0.9676 0.9946 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`